﻿using System.ComponentModel;
using AKit.Framework.Core.Tenant.Dtos;
using AKit.Framework.Core.Tenant.Features.ActivateTenant;
using AKit.Framework.Core.Tenant.Features.CreateTenant;
using AKit.Framework.Core.Tenant.Features.DisableTenant;
using AKit.Framework.Core.Tenant.Features.GetTenantById;
using AKit.Framework.Core.Tenant.Features.GetTenants;
using AKit.Framework.Core.Tenant.Features.UpgradeSubscription;
using Infrastructure.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AilingKit.WebApi.Host.Controllers;

/// <summary>
/// 租户管理
/// </summary>
[AllowAnonymous]
public class TenantsController : BaseController
{
    /// <summary>
    /// 激活
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpPost("{id}/activate")]
    [Description("激活")]
    public async Task<ActivateTenantResponse> Activate(string id)
    {
        return await Mediator.Send(new ActivateTenantCommand(id));
    }

    /// <summary>
    /// 创建
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost]
    [Description("创建")]
    public async Task<CreateTenantResponse> Create(CreateTenantCommand command)
    {
        return await Mediator.Send(command);
    }

    /// <summary>
    /// 禁用
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpPost("{id}/deactivate")]
    [Description("禁用")]
    public async Task<DisableTenantResponse> Disable(string id)
    {
        return await Mediator.Send(new DisableTenantCommand(id));
    }



    /// <summary>
    /// 单条查询
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet("{id}")]
    [Description("单条查询")]
    public async Task<TenantDetail> GetTenantByIdQuery(string id)
    {
        return await Mediator.Send(new GetTenantByIdQuery(id));
    }

    /// <summary>
    /// 全部查询
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [Description("全部查询")]
    public async Task<List<TenantDetail>> GetTenants()
    {
        return await Mediator.Send(new GetTenantsQuery());
    }

    /// <summary>
    /// 更新订阅
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost("upgrade")]
    [Description("更新订阅")]
    public async Task<UpgradeSubscriptionResponse> Disable(UpgradeSubscriptionCommand command)
    {
        return await Mediator.Send(command);
    }
}
